home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Cafe 3
/
Visual Cafe 3.ISO
/
Vcafe
/
Source.bin
/
CompareCells.java
< prev
next >
Wrap
Text File
|
1998-08-21
|
4KB
|
139 lines
package symantec.itools.awt;
import java.util.BitSet;
// 07/14/97 LAB Separeated from Multilist.java. Made public to accommodate future
// extendibility of the MultiList class.
/**
* This is a helper class to the MultiList class.
* It is used to compare Cells of the MultiList.
* @version 1.1, July 14, 1997
* @author Symantec
*/
public abstract class CompareCells
implements CompareFuncCB
{
/**
* Constructs a CompareCells object.
*/
public CompareCells() {
}
/**
* Compares the value of two objects.
* @param o1 the first object
* @param o2 the second object
* @return 0 if the object's values are equal, less than 0 if the first
* object's value is less than the second object's value, and greater
* than 0 if the first object's value is greater than the second
* object's value
*/
public abstract int compareObjects(Object o1, Object o2);
/**
* By default, determines whether the first object's value is less than
* the second's. Calling the <code>reverse</code> method toggles between
* the default behavior and determining the if the first object's value
* is greater than or equal to the second's.
* @param o1 the first object
* @param o2 the second object
* @see #reverse
*/
public boolean lessThan(Object o1, Object o2)
{
int compareResult = compareObjects(o1,o2);
if (lessOrBig)
return compareResult < 0;
return compareResult >= 0;
}
/**
* Notes which rows are hilighted before a sort is performed.
* @param bs flags indicating which rows are hilighted in the MultiList
*/
public void setCurrentBitSet(BitSet bs)
{
this.bs = bs;
}
/**
* Notes which row is selected before a sort is performed.
* @param selRow the zero-relative index of the currently selected row
* @see #getSelectedRow
*/
public void setSelectedRow(int selRow)
{
this.selRow = selRow;
}
/**
* Gets the row which has been noted as selected.
* @see #setSelectedRow
*/
public int getSelectedRow()
{
return selRow;
}
/**
* Exchanges the compared values (rows) in the two given objects.
* @param o1 the first object, a Matrix
* @param o2 the second object, a Matrix
*/
public void callBackSwap(Object o1, Object o2)
{
Matrix m1 = (Matrix)o1;
Matrix m2 = (Matrix)o2;
boolean b1 = bs.get(m1.row);
boolean b2 = bs.get(m2.row);
if (b1)
bs.set(m2.row);
else
bs.clear(m2.row);
if (b2)
bs.set(m1.row);
else
bs.clear(m1.row);
if (selRow == m1.row)
selRow = m2.row;
else if (selRow == m2.row)
selRow = m1.row;
}
/**
* Toggles the comparison done by the <code>lessThan</code> method.
* By default, the <code>lessThan</code> method determines whether the
* first object's value is less than the second's.
* Calling the this method toggles between toggles netween that behavior
* and determining the if the first object's value is greater than or
* equal to the second's.
* @see #lessThan
*/
public void reverse()
{
lessOrBig = !lessOrBig;
}
/**
* A set of flags that indicates which rows are hilighted in the MultiList.
*/
protected BitSet bs;
/**
* The zero-relative index of the currently selected row, or -1 if none.
*/
protected int selRow = -1;
/**
* The current compare mode for the <code>lessThan</code> method.
* If true, the <code>lessThan</code> method determines whether the
* first object's value is less than the second's.
* If false, the <code>lessThan</code> method determines whether the
* first object's value is is greater than or equal to the second's.
* @see #lessThan
* @see #reverse
*/
protected boolean lessOrBig = true;
}